package com.hugehard.here;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Show all About page related issues.
 * 
 * @author andrewpiggy
 */
public class AboutActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about_activity);
		TextView versionTextView = (TextView) findViewById(R.id.app_version);
		try {
			versionTextView.setText("HERE!" + getPackageManager().getPackageInfo(
					getApplication().getPackageName(), 0).versionName);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

		ActionBar actionBar = getActionBar();
		actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setDisplayHomeAsUpEnabled(true);
		actionBar.setHomeButtonEnabled(true);

		LinearLayout rateHereItem = (LinearLayout) findViewById(R.id.rate_here_item);
		rateHereItem.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_VIEW);
				intent.setData(Uri
						.parse("market://details?id=com.hugehard.infinitepanorama"));
				startActivity(intent);
			}
		});

		LinearLayout aboutHereItem = (LinearLayout) findViewById(R.id.about_here_item);
		aboutHereItem.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(AboutActivity.this,
						IntroductionViewPager.class);
				startActivity(intent);
			}
		});

		LinearLayout herefeatureItem = (LinearLayout) findViewById(R.id.here_feature_item);
		herefeatureItem.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(AboutActivity.this,
						HereFeatureActivity.class);
				startActivity(intent);
			}
		});
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem menuItem) {
		if (menuItem.getItemId() == android.R.id.home) {
			Intent intent = new Intent(AboutActivity.this, MainActivity.class);
			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
			return true;
		}
		return super.onOptionsItemSelected(menuItem);
	}
}
